package org.zephyr.project.orm.autoconfig;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * @author yu.zhang
 * @date 2019-10-09
 */
@Configuration
@EnableConfigurationProperties(DataSourceProperties.class)
public class DataSourceAutoConfig {
    private DataSourceProperties properties;

    public DataSourceAutoConfig(DataSourceProperties properties) {
        this.properties = properties;
    }

    @Bean
    public DataSource dataSource() {
        return new DriverManagerDataSource(
                properties.getUrl(),
                properties.getUsername(),
                properties.getPassword()
        );
    }
}
